﻿$(document).ready(function () {

    var EMAILID = $("#USER_MAIL_ID").val()
    if (EMAILID != "") {
        $("#login-link").hide();
        $("#logout-link").show();
    } else {
        $("#login-link").show();
        $("#logout-link").hide();
    }
    $(".seat").click(function () {
        var val = $(this).val();
        if ($(this).hasClass("seatSelected")) {
            $(this).removeClass("seatSelected");
            $('#' + val).remove();
            return false;
        }
        var no_of_seats_selected = $(".seatnumber").length;
        if (no_of_seats_selected < 5) {
            $(this).addClass("seatSelected");
            //  $(this).attr("disabled", true);

            //var newElem = $('<input>').attr("type", "hidden").attr("id", val);
            $('<input>').attr("type", "hidden").attr("id", val).attr("name", "seatnumber").addClass("seatnumber").appendTo("#seatForm");
        } else {
            alert("More than 5 seats are not allowed.");
        }
        return false;
    });

    $(".paymentButton").click(function () {
        var seats = "";

        $(".seatnumber").each(function () {
            
            seats += this.id + "|";
        });
        $("#MainContent_HiddenField1").val(seats);
    });

    $("#loginbtn").click(function () {

        var emailID = $("#login-email").val();
        var password = $("#login-psw").val();
        if (emailID == null || emailID == "") {
            alert("Please Enter Email ID");
            return false;
        }
        if (password == null || password == "") {
            alert("Please Enter Password");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "Default.aspx/login",
            data: "{'emailID' : '" + emailID + "','password':'" + password + "'}",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (msg) {

                if (msg.d == "True") {

                    location.reload();

                } else {
                    alert(msg.d);

                }
            },
            error: function (x, e) {
                alert("The call to the server side failed. " + x.responseText);
            }
        });
        return false;

    });

    $("#logout-link").click(function () {
        
        $.ajax({
            type: "POST",
            url: "Default.aspx/logout",
            data: "{}",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (msg) {
                location.reload();
            },
            error: function (x, e) {
                alert("The call to the server side failed. " + x.responseText);
            }
        });
        return false;

    });

    $("#signupbtn").click(function () {
        var emailID = $("#registration-email").val();
        var password = $("#registration-pwd").val();
        var name = $("#registration-name").val();
        var mno = $("#registration-mno").val();
        var notifyme = $("#registration-cb").attr('checked');

        if (notifyme) {
            var notifymeStr = "true";

        } else {
            var notifymeStr = "false";

        }
        if (name == null || name == "") {
            alert("Please Enter Name");
            return false;
        }

        if (emailID == null || emailID == "") {
            alert("Please Enter Email ID");
            return false;
        }

        if (password == null || password == "") {
            alert("Please Enter Password");
            return false;
        }

        $.ajax({
            type: "POST",
            url: "Default.aspx/signup",
            data: "{'name' : '" + name + "','emailID' : '" + emailID + "','password':'" + password + "','mobileNo' : '" + mno + "','notifyme' : '" + notifymeStr + "'}",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (msg) {

                if (msg.d == "True") {
                    alert("Registration is successful..");
                    $("#registration_menu").hide();
                    location.reload();
                } else {
                    alert(msg.d);
                }
            },
            error: function (x, e) {
                alert("The call to the server side failed. " + x.responseText);
            }
        });
        return false;
    });


});
